package top.glkj.hms.controller.system;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.glkj.hms.entity.Resource;
import top.glkj.hms.exception.DefineException;
import top.glkj.hms.service.ResourceService;
import top.glkj.hms.utils.Result;

/**
 * @author : xgl
 * @version : 0.0.1
 * @date :2020/12/21 0:54
 */
@Api(tags = "资源管理")
@RestController
@RequestMapping("/system/resource")
public class ResourceManagementController {
    private final ResourceService resourceService;

    @Autowired
    public ResourceManagementController(ResourceService resourceService) {
        this.resourceService = resourceService;
    }

    @GetMapping
    @ApiOperation("获取所有资源")
    public Result getAll() {
        return resourceService.getAll();
    }

    @ApiOperation("分页获取资源")
    @GetMapping("/{size}/{page}")
    public Result getAll(@PathVariable(name = "size") Integer size, @PathVariable(name = "page") Integer page) throws DefineException {
        return resourceService.getResourcesByPageAndSize(page,size);
    }



    @ApiOperation("添加资源")
    @PostMapping
    public Result addResource(Resource resource) {
        return resourceService.addResource(resource);
    }

    @ApiOperation("修改资源")
    @PutMapping
    public Result updateResource(Resource resource) throws DefineException {
        return resourceService.updateResource(resource);
    }

    @ApiOperation("删除资源")
    @DeleteMapping
    public Result removeResource(Resource resource) throws DefineException {
        return resourceService.remove(resource);
    }

    @ApiOperation("彻底删除资源")
    @DeleteMapping("/delete")
    public Result deleteResource(Resource resource) throws DefineException {
        return resourceService.delete(resource);
    }
}
